//
//  baseshader.h
//  xed_vfx_engine
//
//  Created by 岳伸 富田 on 11/10/28.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#ifndef xed_vfx_engine_baseshader_h
#define xed_vfx_engine_baseshader_h

#include "common.h"
#include <vector>

namespace Graphic {

typedef int ShaderID;

#define MAX_UNIFORMLOCATION_SET 16
typedef struct UniformLocationSet
{
  unsigned int uniformLocationCount;
  GLint uniformLocations[MAX_UNIFORMLOCATION_SET];
} UniformLocationSet;

#define SPECIFIC_UNIFORMLOCATION_COUNT 4
typedef struct SpecificUniformLocations
{
  GLint uniformLocationWorld;
  GLint uniformLocationView;
  GLint uniformLocationProj;
  GLint uniformLocationWorldViewProj;
} SpecificUniformLocations;

typedef struct ShaderSet
{
  GLuint shader;
  UniformLocationSet uniformLocationSet;
  SpecificUniformLocations specificUniformLocations;
} ShaderSet;

class BaseShader
{
public:
  BaseShader(){}
  virtual ~BaseShader(){}
  
  virtual bool Init()=0;
  virtual void Destroy()=0;
  
  virtual bool ActivateUniformLocation(const ShaderID shaderId, const char* locName, unsigned int locIndex);
  virtual bool Bind(const ShaderID shaderId);
  virtual void Unbind();
  
  virtual void SetWVP(const VMA::Matrix4& wvp);
  virtual void SetWorldMatrix(const VMA::Matrix4& world);
  virtual void SetViewMatrix(const VMA::Matrix4& view);
  virtual void SetProjMatrix(const VMA::Matrix4& proj);
  
  virtual void SetUniform4fv(unsigned int locIndex, const float* value, unsigned int arrayCount=4);
  virtual void SetUniform4f(unsigned int locIndex, const VMA::Vector4& v);

  virtual void SetUniformMatrix4fv(unsigned int locIndex, const float* value, unsigned int arrayCount=16);
  virtual void SetUniformMatrix4f(unsigned int locIndex, const VMA::Matrix4& m);

protected:
  ShaderID buildShader(const char* vertexShadrSource, const char* fragmentShaderSource);
  
protected:
  std::vector<ShaderSet> m_shaderSets;

private:
  ShaderID m_currentShaderId;
}; // class BaseShader

} // namespace Graphic { 
#endif
